package com.edfu.core.institutemgt.persistence.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;


/**
 * 
 * @author sahsharm
 *This class represents a branch , for example Computer Science , Civil , Mechanical etc. For schools it can be a class like Standard 9th,
 */

@Entity
@Table(name="branch", uniqueConstraints=@UniqueConstraint(columnNames={"code" , "institute_id"}))
public class BranchEntity implements IInstituteMgtEntity {
	private long id;
	private String code;
	private String title;
	private String description;
	private Date createdOn;
	private Date lastModifiedOn;
	private BranchEntity parentBranch;
	private InstituteEntity institute;
	private Set<BranchMemberEntity> members;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Date getCreatedOn() {
		return createdOn;
	}
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}
	public Date getLastModifiedOn() {
		return lastModifiedOn;
	}
	public void setLastModifiedOn(Date lastModifiedOn) {
		this.lastModifiedOn = lastModifiedOn;
	}
	
	@ManyToOne
	@JoinColumn(name = "parent_branch_id", nullable = true)
	public BranchEntity getParentBranch() {
		return parentBranch;
	}
	public void setParentBranch(BranchEntity parentBranch) {
		this.parentBranch = parentBranch;
	}
	
	@ManyToOne
	@JoinColumn(name = "institute_id", nullable = false)
	public InstituteEntity getInstitute() {
		return institute;
	}
	public void setInstitute(InstituteEntity institute) {
		this.institute = institute;
	}
	
	@OneToMany(mappedBy = "branch", fetch= FetchType.EAGER)
	public Set<BranchMemberEntity> getMembers() {
		return members;
	}
	public void setMembers(Set<BranchMemberEntity> members) {
		this.members = members;
	}
	
}
